from typing import Dict, Any, List
from .base_service_handler import BaseServiceHandler, ServiceHandlerFactory

class SSHServiceHandler(BaseServiceHandler):
    """SSH服务信息处理器"""
    
    def get_service_details(self, service_info: Dict[str, Any]) -> List[str]:
        """获取SSH服务的详细信息"""
        details = []
        
        # 基本信息
        if service_info.get('product'):
            details.append(f"产品: {self._safe_str(service_info['product'])}")
        if service_info.get('version'):
            details.append(f"版本: {self._safe_str(service_info['version'])}")
        if service_info.get('banner'):
            details.append(f"Banner: {self._safe_str(service_info['banner'])}")
            
        # SSH特定信息
        ssh_fields = {
            'protocol_version': 'SSH协议版本',
            'key_type': '密钥类型',
            'key_bits': '密钥长度',
            'fingerprint': '密钥指纹',
            'auth_methods': '认证方式',
            'encryption_algorithms': '加密算法'
        }
        
        for field, label in ssh_fields.items():
            if service_info.get(field):
                value = service_info[field]
                if isinstance(value, list):
                    details.append(f"{label}: {', '.join(map(self._safe_str, value))}")
                else:
                    if field == 'key_bits':
                        details.append(f"{label}: {self._safe_str(value)}位")
                    else:
                        details.append(f"{label}: {self._safe_str(value)}")
                        
        return details

# 注册SSH服务处理器
ServiceHandlerFactory.register_handler('ssh', SSHServiceHandler) 